﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PoemCrawler
{
    internal static class DownloadString
    {
        public static async Task<AsyncResult<string>> DownloadStringAsync(string url)
        {
            using var client = new HttpClient();
            try
            {
                HttpResponseMessage response = await client.GetAsync(url);
                response.EnsureSuccessStatusCode();  // 确保请求成功
                string responseBody = await response.Content.ReadAsStringAsync();
                return new(responseBody);
            }
            catch (HttpRequestException e)
            {
                return new(e);
            }
        }
    }
}
